package com.jianbing.entity;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Han, Tixiang on 2016/9/23 0023.
 */

public class Page<T>{
    //查询记录数
    private int totalRecords = 0;

    //每页多少条数据
    private int pageSize = 20;

    //第几页
    private int currentPage = 1;

    //结果集
    private List<T> list = new ArrayList<T>();
    /**
     * 总页数
     * @return
     */
    public int getTotalPages() {
        return (totalRecords + pageSize - 1) / pageSize;
    }

    /**
     * 取得首页
     * @return
     */
    public int getFirstPage() {
        return 1;
    }

    /**
     * 上一页
     * @return
     */
    public int getPrevPage() {
        if (currentPage <= 1) {
            return 1;
        }
        return currentPage - 1;
    }

    /**
     * 下一页
     * @return
     */
    public int getNextPage() {
        if (currentPage >= getTotalPages()) {
            return getTotalPages();
        }
        return currentPage + 1;
    }

    /**
     * 取得尾页
     * @return
     */
    public int getLastPage() {
        return getTotalPages();
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public List<T> getList() {
        return list;
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }
}